#include <bits/stdc++.h>
using namespace std;

int m, n;

bool isString(int i){
    string str = to_string(i);
    string need = to_string(n);
    return str.find(need) != string::npos;
}

int main(){
    cin >> m >> n;
    vector<int> ans;
    for(int i = 1; i <= m; ++i){
        if(i % n == 0 || isString(i)){
            ans.push_back(i);
        }
    }
    int l = ans.size();
    for(int i = 0; i < l; ++i){
        cout << ans[i];
        if(i != l - 1) cout << " ";
    }
}